<template>
  <div id="globalSider">
    <a-layout-sider
      v-if="loginUserStore.loginUser.id"
      width="200"
      breakpoint="lg"
      collapsed-width="0"
    >
      <a-menu
        v-model:selectedKeys="current"
        mode="inline"
        :items="menuItems"
        @click="doMenuClick"
      />
    </a-layout-sider>
  </div>
</template>
<script lang="ts" setup>
import { h, ref } from 'vue'
import { PictureOutlined, UserOutlined } from '@ant-design/icons-vue'
import { useRouter } from 'vue-router'
import { useLoginUserStore } from '@/stores/useLoginUserStore.ts'

const loginUserStore = useLoginUserStore()

// 菜单项
const menuItems = [
  {
    key: '/',
    icon: () => h(PictureOutlined),
    label: '公共图库',
  },
  {
    key: '/my_space',
    label: '我的空间',
    icon: () => h(UserOutlined),
  },
]

const router = useRouter()
// 当前要高亮的菜单项
const current = ref<string[]>([])
// 监听路由变化，更新高亮菜单项
router.afterEach((to, from, next) => {
  current.value = [to.path]
})

// 路由跳转事件
const doMenuClick = ({ key }) => {
  router.push({
    path: key,
  })
}
</script>

<style scoped>
#globalSider .ant-layout-sider {
  background: transparent;
}

:deep(.ant-menu-inline) {
  border-right: none;
  background: transparent;
}

:deep(.ant-menu-item) {
  margin: 8px 12px !important;
  padding: 0 16px !important;
  border-radius: 8px;
  color: #666;
  height: 48px !important;
  line-height: 48px !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

:deep(.ant-menu-item.ant-menu-item-selected) {
  background: linear-gradient(135deg, #ffeaea 0%, #fff6f6 100%);
  color: #d4463d;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(212, 70, 61, 0.1);
}

:deep(.ant-menu-item:hover) {
  color: #d4463d !important;
  background: rgba(255, 228, 228, 0.5) !important;
  transform: translateX(4px);
}

:deep(.ant-menu-item::after) {
  display: none;
}

:deep(.anticon) {
  color: inherit;
  font-size: 18px;
  transition: transform 0.3s;
}

:deep(.ant-menu-item:hover .anticon) {
  transform: scale(1.1);
}

:deep(.ant-menu-item-selected .anticon) {
  transform: scale(1.1);
}

:deep(.ant-menu-title-content) {
  margin-left: 12px;
}
</style>
